package com.gui.mianshiya.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gui.mianshiya.common.BaseResponse;
import com.gui.mianshiya.common.ResultUtils;
import com.gui.mianshiya.model.dto.multiQuestion.MultiQuestionQueryRequest;
import com.gui.mianshiya.model.dto.multiQuestion.MultiQuestionRecordRequest;
import com.gui.mianshiya.model.entity.MultiQuestion;
import com.gui.mianshiya.model.entity.MultiQuestionRecords;
import com.gui.mianshiya.model.entity.User;
import com.gui.mianshiya.service.MultiQuestionRecordsService;
import com.gui.mianshiya.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @Title: MultiQuestionRecordsController
 * @Author quit
 * @Package com.gui.mianshiya.controller
 * @Date 2025/5/12 19:43
 * @description:
 */
@RestController
@Slf4j
public class MultiQuestionRecordsController {


    @Resource
    private MultiQuestionRecordsService multiQuestionRecordsService;

    @Resource
    private UserService userService;

    @PostMapping("/multi/record")
    public BaseResponse<Boolean> MultiQuestionRecord(@RequestBody MultiQuestionRecordRequest multiQuestionRecordRequest, HttpServletRequest request) {
        User loginUser = userService.getLoginUser(request);
        for (Long multiQuestionId : multiQuestionRecordRequest.getMultiQuestionIds()) {
            MultiQuestionRecords multiQuestionRecords = new MultiQuestionRecords();
            for (Long wrongQuestionId : multiQuestionRecordRequest.getWrongQuestionIds()) {
                if (wrongQuestionId .equals(multiQuestionId) ) {
                    multiQuestionRecords.setWrongType(1);
                }
            }
            multiQuestionRecords.setMultiQuestionId(multiQuestionId);
            multiQuestionRecords.setUserId(loginUser.getId());
            multiQuestionRecords.setQuestionBankId(multiQuestionRecordRequest.getQuestionBankId());
            multiQuestionRecords.setCreateTime(new Date());
            boolean save = multiQuestionRecordsService.saveOrUpdate(multiQuestionRecords);
        }
        return ResultUtils.success(Boolean.TRUE);
    }
    @PostMapping("/multi/remark")
    public BaseResponse<Boolean> MultiQuestionRemark(@RequestBody   MultiQuestionRecordRequest multiQuestionRecordRequest, HttpServletRequest request) {
        User loginUser = userService.getLoginUser(request);
        LambdaQueryWrapper<MultiQuestionRecords> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MultiQuestionRecords::getQuestionBankId, multiQuestionRecordRequest.getQuestionBankId());
        queryWrapper.eq(MultiQuestionRecords::getUserId, loginUser.getId());
        boolean remove = multiQuestionRecordsService.remove(queryWrapper);
        return ResultUtils.success(remove);
    }
}
